<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-shuixi-shenpi" th:object="${shuixi}">
        <input id="sxId" name="sxId" th:field="*{sxId}"  type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">详细内容：</label>
            <div class="col-sm-8">
                <input id="sxShenpi" name="sxShenpi" th:field="*{sxShenpi}" type="hidden">
                <div id="shenpior" class="summernote"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审批状态：</label>
            <div class="col-sm-8">
                <select id="sxStatus" class="form-control m-b" th:with="type=${@dict.getType('sys_approval_status')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sxStatus}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "system/shuixi";

    $(function() {
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        var content = $("#sxShenpi").val();
        $('#shenpior').summernote('code', content);
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    // $(obj).summernote('shenpior.insertImage', result.url, result.fileName);
                    $(obj).summernote('editor.insertImage', img_root + result.fileName, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }

    // $("#form-shuixi-shenpi").validate({
    //     rules:{
    //         xxxx:{
    //             required:true,
    //         },
    //     },
    //     focusCleanup: true
    // });
    function submitHandler() {
        var formdata = new FormData();
        formdata.append("sxShenpi", $('.summernote').summernote('code'));
        formdata.append("sxStatus", $("#sxStatus option:selected").val());
        formdata.append("sxId", [[${shuixi.sxId}]]);
        $.ajax({
            url: ctx + "system/shuixi/shenpiSave",
            data: formdata,
            type: "post",
            processData: false,
            contentType: false,
            success: function (result) {
                $.operate.saveSuccess(result);
            }
        })


        // if ($.validate.form()) {
        //     var sHTML = $('.summernote').summernote('code');
        //     $("#sxDetails").val(sHTML);
        //     $.operate.save(prefix + "/shenpi", $('#form-shuixi-shenpi').serialize());
        // }

    }
</script>
</body>
</html>
